Skip to main content
Version: 6.0.10

execute.js

execute.js is configuration of JavaScript logic when action is executed.

With predefined variables, user can create their own logic for action.

Expected input/output

  • Execution input
    • Contains request body data for API execution.
    • needs to follow the schema/variables configured in data.json.
  • Execution output
    • output will contain result data from API execution for further executions.
      • e.g. Action(gmail email.send) -> Output(sent email info)
    • needs to follow the schema/output configured in data.json.

Example execute.js

try {
const message_data = {
"to": input.data.to,
"cc": input.data.cc || [],
"bcc": input.data.bcc || [],
"from": input.data.from_name ? await service.fn.string_to_qp({ "string": `${input.data.from_name} <${input.data.from}>` }) : input.data.from || "",
"subject": await service.fn.string_to_qp({ "string": input.data.subject }),
"body": input.data.body,
"bodyType": (input.data.signature || input.data.bodyType === "html") ? "html" : "plain",
"signature": input.data.signature || ""
}

const response = await $.axios({
method: "post",
url: `https://www.googleapis.com/gmail/v1/users/me/messages/send`,
headers: {
"Authorization": `Bearer ${service.token}`,
"Content-Type": "application/json"
},
data: {
"raw": await service.fn.create_raw_message(message_data),
"labelIds": input.data.labelIds || []
}
})

const email_info = await service.fn.get_email_info({ "id": response.data.id, "service_token": service.token }, $)
email_info["message_info"] = await service.fn.get_payload_info(email_info.payload)

return email_info
} catch (error) {
throw error
}